package progress.exa30_1;

import java.lang.reflect.AccessibleObject;
import java.lang.reflect.Field;
import java.util.ArrayList;

public class FieldStudy {
    public static void main(String[] args) throws IllegalAccessException {
        getFiled();
    }

    public static void getFiled() throws IllegalAccessException {
        Class<?> cl = ArrayList.class;
        ArrayList arrayList = new ArrayList();
        Field [] fields = cl.getDeclaredFields();
        AccessibleObject.setAccessible(fields,true);
        for(Field field:fields){
            System.out.println(field.getName()+":"+ field.get(arrayList));
            if(field.getName().equals("size")){
                System.out.println("修改size的值为12");
                field.set(arrayList,12);
                System.out.println("修改后的值"+field.getName()+":"+ field.get(arrayList));
            }

        }
    }

}
